package jdbc;

import java.sql.*;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            /*
            select id,username,password,nickname,age
            from userinfo
            where username='"+username+"'
            and password='"+password+"'
             */
            String sql = "select id,username,password,nickname,age " +
                    "from userinfo " +
                    "where username=? and password=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1, "aaa");
            ps.setString(2, "123456");
            ResultSet rs = ps.executeQuery();
            System.out.println("正在登录......");
            if (rs.next()) {
                String nickname = rs.getString("nickname");
                System.out.println("登陆成功！欢迎回来." + nickname);
            }else{
                System.out.println("登陆失败！用户名或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
